package com.health.ts.controller.sysmanage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.health.ts.constant.ApiResult;
import com.health.ts.constant.FrontPage;
import com.health.ts.controller.BaseController;
import com.health.ts.entity.sysmanage.SysDepartment;
import com.health.ts.service.sysmanage.SysDepartmentService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 基础信息维护-科室管理
 * @author Administrator
 */
@Api(value = "基础信息维护-科室管理", tags = {"基础信息维护-科室管理"})
@RestController
@RequestMapping(value = "/api/baseInfo",produces= BaseController.JSON_UTF8)
public class DepartmentController extends BaseController{
	
	/**
	 * 科室信息服务
	 */
	@Autowired
	SysDepartmentService sysDepartmentService;
	
	/**
	 * 科室分页列表
	 * @param page
	 * @return
	 */
	@ApiOperation(value = "室分页列表", notes = "室分页列表")
	@RequestMapping(value = "/departmentsPager",method=RequestMethod.GET)
	public ApiResult listDepartmentPager(FrontPage page) {
		return ApiResult.success(sysDepartmentService.selectDepartmentPage(page));
	}
	
	/**
	 * 查询科室列表(不带分页)
	 * @return
	 */
	@ApiOperation(value = "查询科室列表(不带分页)", notes = "查询科室列表(不带分页)")
	@RequestMapping(value = "/departments",method=RequestMethod.GET)
	public ApiResult listDepartment(@RequestParam("hospital_id") String hospitalId) {
		return ApiResult.success(sysDepartmentService.listDepartment(hospitalId));
	}
	
	/**
	 * 获取单个科室
	 * @param id
	 * @return
	 */
	@ApiOperation(value = "获取单个科室", notes = "获取单个科室")
	@RequestMapping(value="/department/{id}", method=RequestMethod.GET)
	public ApiResult selectDepartment(@PathVariable String id) {
		return ApiResult.success(sysDepartmentService.selectDepartment(id));
	}
	
	/**
	 * 创建科室
	 * @param department
	 * @return
	 */
	@ApiOperation(value = "创建科室", notes = "创建科室")
	@RequestMapping(value="/department", method=RequestMethod.POST)
	public ApiResult addDepartment(@RequestBody SysDepartment department) {
		sysDepartmentService.addDepartment(department);
		return ApiResult.success();
	}
	
	/**
	 * 科室信息修改
	 * @param hospital
	 * @return
	 */
	@ApiOperation(value = "科室信息修改", notes = "科室信息修改")
	@RequestMapping(value="/department/{id}", method=RequestMethod.PUT)
	public ApiResult updateDepartment(@PathVariable String id,@RequestBody SysDepartment department) {
		sysDepartmentService.updateDepartment(id, department);
		return ApiResult.success();
	}
	
	/**
	 * 删除科室
	 * @param id
	 * @return
	 */
	@ApiOperation(value = "删除科室", notes = "删除科室")
	@RequestMapping(value="/department/{id}", method=RequestMethod.DELETE)
	public ApiResult deleteDepartment(@PathVariable String id) {
		sysDepartmentService.deleteDepartment(id);
		return ApiResult.success();
	}
}
